<template>
  <div class="os-main">
    <ConfigForm v-model="dataForm" :config="config" ref="configFormRef" />

    <el-button type="primary" @click="openJson">查看表单数据</el-button>

    <el-drawer v-model="drawerVisiable" title="数据视图" :direction="'rtl'" size="40%">
      <CodeView :code-json="JSON.stringify(dataForm, null, '\t')"></CodeView>
    </el-drawer>
  </div>
</template>

<script lang="ts" setup>
import type { Config } from '@/components/ConfigForm'
import { ref } from 'vue';
import CodeView from '@/components/CodeView/index.vue'
import ConfigForm from '@/components/ConfigForm/index'

/**ConfigForm绑定对象 */
const dataForm = ref<ObjectAny>({})

/**ConfigForm配置 */
const config = ref<Config>({
  mode: 'add',
  formProps: {},
  rowProps: {},
  columns: [
    { // 基础用法
      prop: 'demo1', label: '基础用法', value: 0, type: 'inputNumber',
      props: {
        style: { width: 'auto' },
        min: -5,
        max: 10
      },
      events: {
        change: (val: number) => { console.log(val); }
      }
    },
    { prop: 'demo2', label: '禁用状态', type: 'inputNumber', props: { disabled: true } },
    { prop: 'demo3', label: '步进', value: 0, type: 'inputNumber', props: { step: 5 } },
    { prop: 'demo4', label: '严格步进', value: 2, type: 'inputNumber', props: { step: 2, stepStrictly: true } },
    { prop: 'demo5', label: '精度', value: 1.00, type: 'inputNumber', props: { step: 0.1, precision: 2 } },
    {
      prop: 'demo6', label: '按钮位置', value: 0, type: 'inputNumber',
      props: { controlsPosition: 'right' },
      events: { change: (val: number) => { console.log(val); } }
    },
  ]
})

// 数据视图
const drawerVisiable = ref(false)
const openJson = () => {
  drawerVisiable.value = true
}
</script>
